<template>
  <el-dialog
      :close-on-click-modal="false"
      :visible.sync="obtainScoreVisible">
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="80px">

      <el-form-item label="得分" prop="actualScore">
        <el-input type="number" v-model="dataForm.actualScore" placeholder="得分"></el-input>
      </el-form-item>

      <el-form-item label="评语" prop="teacherNotes">
        <el-input  type="textarea" v-model="dataForm.teacherNotes" placeholder="评语"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="obtainScoreVisible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {submitScore} from '@/api/teacher/workTask'
import {fetchCourseList} from '@/api/teacher/course'

export default {
  data() {
    return {
      totalScore: '',
      obtainScoreVisible: false,
      dataForm: {
        id: 0,
        actualScore: '',
        teacherNotes: ''
      },

    }
  },

  methods: {

    init(id,totalScore) {
      this.dataForm.id = id
      this.dataForm.actualScore = totalScore
      this.totalScore=totalScore;
      this.obtainScoreVisible = true;
    },
    // 表单提交
    dataFormSubmit() {

      if(!this.dataForm.actualScore){
        this.$notify.error('请打分')
        return
      }

      if(this.totalScore<this.dataForm.actualScore){
        this.$notify.error('分值已经超过总分')
        return
      }
      submitScore(this.dataForm).then(data => {
        this.$notify.success('打分成功')
        this.obtainScoreVisible = false
        this.$emit('refreshDataList')
      })
    }
  }
}
</script>
